package org.mspring.mlog.api.spider.entity;

import java.io.Serializable;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import org.mspring.mlog.entity.Job;

/**
 * 发布规则
 * 
 * @author Gao Youbo
 * @since 2013年7月22日
 */
@Entity
@Table(name = "spider_publish_rule")
public class PublishRule implements Serializable {

    private static final long serialVersionUID = -6288867967012933296L;

    private Long id;
    private String name;
    private SpiderRule rule; // 抓取规则
    private Long publishCatalog; // 发布分类
    private Long publishAuthor; // 发布人
    private Job job; // JOB
    private Long timeInterval; // 每篇文章采集过程中的时间间隔，防止被服务器列入黑名单
    private Boolean autoPublish = true; // 是否自动发布文章

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id", unique = true, nullable = false, length = 30)
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    @Column(name = "name", nullable = false, length = 100)
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @ManyToOne(fetch = FetchType.EAGER, optional = false, targetEntity = SpiderRule.class)
    @JoinColumn(name = "spider_rule", nullable = false)
    public SpiderRule getRule() {
        return rule;
    }

    public void setRule(SpiderRule rule) {
        this.rule = rule;
    }

    @Column(name = "publish_catalog", nullable = false, length = 20)
    public Long getPublishCatalog() {
        return publishCatalog;
    }

    public void setPublishCatalog(Long publishCatalog) {
        this.publishCatalog = publishCatalog;
    }

    @Column(name = "publish_author", nullable = false, length = 20)
    public Long getPublishAuthor() {
        return publishAuthor;
    }

    public void setPublishAuthor(Long publishAuthor) {
        this.publishAuthor = publishAuthor;
    }

    @ManyToOne(fetch = FetchType.EAGER, optional = false, cascade = { CascadeType.ALL }, targetEntity = Job.class)
    @JoinColumn(name = "job", unique = true)
    public Job getJob() {
        return job;
    }

    public void setJob(Job job) {
        this.job = job;
    }

    @Column(name = "time_interval", length = 20)
    public Long getTimeInterval() {
        return timeInterval;
    }

    public void setTimeInterval(Long timeInterval) {
        this.timeInterval = timeInterval;
    }

    @Column(name = "auto_publish")
    public Boolean getAutoPublish() {
        return autoPublish;
    }

    public void setAutoPublish(Boolean autoPublish) {
        this.autoPublish = autoPublish;
    }

}
